package com.jt.config;

import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import com.alibaba.fastjson.JSON;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.HashMap;

@Configuration
public class ResourceGateWay {
        public ResourceGateWay(){
                GatewayCallbackManager.setBlockHandler(new BlockRequestHandler() {
                        @Override
                        public Mono<ServerResponse> handleRequest(ServerWebExchange serverWebExchange, Throwable throwable) {
                                HashMap<String, Object> map = new HashMap<>();
                                map.put("error",520);
                                map.put("message","稍等一下");
                                String s = JSON.toJSONString(map);
                                return ServerResponse.ok().body(Mono.just(s),String.class);
                        }
                });
        }
}
